from selenium import webdriver

from Buiness.LoginPage import LoginPage
from common.BasePage import BasePage
from Buiness.Back_stagePage import Back_stagePage

class Add_members(BasePage):
    def __init__(self,driver=None):
        super().__init__(driver)
        # self.system_manage_loc = "xpath,//*[@id='s-menu-superadmin']/button"
        # self.system_manage_frame_name="iframe-superadmin"

        self.back_stage_manage="xpath,/html/body/div[1]/div[1]/div/ul[1]/li[8]/button/i"
        self.add_members="xpath,/html/body/div[2]/div/div/div[1]/div/a/h3"
        self.username="id,account"
        self.realname="id,realname"
        self.sex_man="id,genderm"
        self.sex_wamen="id,genderf"
        self.role="id,role"
        self.password1="id,password1"
        self.password2="id,password2"
        self.email="id,email"
        self.save="id,submit"
        self.assert_lenmax ='xpath,//*[@id="accountLabel"]'
        self.assert_password='xpath,//*[@id="password1Label"]'
        self.assert_namepass='xpath,// *[ @ id = "realnameLabel"]'

    def click_add_members(self):
        self.click(self.add_members)
        self.wait(2)


    def enter_username(self,username):
        self.input(self.username,username)
        self.wait(1)

    def enter_realname(self,realname):
        self.input(self.realname,realname)
        self.wait(1)

    def click_man(self):
        self.click(self.sex_man)
        self.wait(1)

    def click_wamen(self):
        self.click(self.sex_wamen)
        self.wait(1)

    def select_role(self,num):
        self.dropdown(self.role,num)
        self.wait(1)

    def enter_password1(self,password1):
        self.input(self.password1,password1)
        self.wait(1)

    def enter_password2(self, password2):
        self.input(self.password2, password2)
        self.wait(1)

    def enter_email(self,email):
        self.input(self.email,email)
        self.wait(1)

    def click_save(self):
        self.click(self.save)
        self.wait(2)

    def get_assert_lenmax(self):
        return self.get_ele_text(self.assert_lenmax)

    def get_assert_password(self):
        return self.get_ele_text(self.assert_password)

    def get_assert_namepass(self):
        return self.get_ele_text(self.assert_namepass)

    def test_addmember(self,username="张飞",
                       realname="翼德",
                       num=2,
                       password1="123456",
                       password2="123456",
                       email="123@qq.com"):
        back = Back_stagePage(driver=self.driver)
        back.test_back()
        self.click_add_members()
        self.enter_username(username)
        self.enter_realname(realname)
        self.click_man()
        self.select_role(num)
        self.enter_password1(password1)
        self.enter_password2(password2)
        self.enter_email(email)
        self.click_save()

if __name__ == '__main__':
    add=Add_members()
    add.test_addmember()


